package com.jy.api.domain;

import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by hanxi on 2017/8/17.
 * 会员充值表
 */
@Entity
@Data
@NoArgsConstructor
public class MemberAccountTransaction {
    @Id
    @Column(length = 50)
    private String id;
    private String memberId;
    private String storeId;
    /**
     * 变化前会员储值金额
     */
    private double amountBefore = 0;
    /**
     * 变化后会员储值金额
     */
    private double amountAfter = 0;
    /**
     * 变化前会员奖励金额
     */
    private double bonusBefore = 0;
    /**
     * 变化后会员奖励金额
     */
    private double bonusAfter = 0;
    @Enumerated(EnumType.STRING)
    private MemberAccountTransactionType type;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;
    private String orderId;
    private String paymentId;
    /**
     * 充值或消费的会员储值金额
     */
    private double amount = 0;
    /**
     * 充值或消费的会员奖励金额
     */
    private double bonus = 0;

    private boolean enabled = true;

    public MemberAccountTransaction(String id, String memberId, String storeId, double amountBefore, double bonusBefore,
                                    MemberAccountTransactionType type, String orderId, String paymentId) {
        this.id = id;
        this.memberId = memberId;
        this.storeId = storeId;
        this.amountBefore = amountBefore;
        this.bonusBefore = bonusBefore;
        this.type = type;
        this.orderId = orderId;
        this.paymentId = paymentId;
    }

    /**
     * 会员账号变更记录
     *
     * @param id
     * @param memberId
     * @param storeId
     * @param amountBefore
     * @param amountAfter
     * @param bonusBefore
     * @param bonusAfter
     * @param type
     * @param orderId
     * @param paymentId
     * @param amount
     * @param bonus
     */
    public MemberAccountTransaction(String id, String memberId, String storeId, double amountBefore, double amountAfter, double bonusBefore, double bonusAfter,
                                    MemberAccountTransactionType type, String orderId, String paymentId, double amount, double bonus) {
        this.id = id;
        this.memberId = memberId;
        this.storeId = storeId;
        this.amountBefore = amountBefore;
        this.amountAfter = amountAfter;
        this.bonusBefore = bonusBefore;
        this.bonusAfter = bonusAfter;
        this.type = type;
        this.orderId = orderId;
        this.paymentId = paymentId;
        this.amount = amount;
        this.bonus = bonus;
    }
}
